<template>
    <div class="share-img">
        <img :src="imgUrl">
    </div>
</template>
<script>
import wxShare from '../../config/couponShare.js';
export default {
    name: "couponShare",
    data() {
        return {
            QINIUtoken: '',
            imgUrl: '',
            contSource: {},
            couponSource: {},
        };
    },
    methods: {

        // 方法
        getImages() {
            let _this = this;
            let params = {
                // url: location.href.split('#')[0] + '?share_id=' + localStorage.getItem('token') + '&from=123',
                url: 'http://wangzhuan.3todo.cn/?share_id=' + localStorage.getItem('token') + '&coupon_id=' + this.$route.query.id + '&from=123',
                coupon_id: this.$route.query.id,

            };
            console.log(1123);
            this.$post("/coupon/get_share_img", params)
                .then(res => {
                    if (res.code === 20000) {
                        this.imgUrl = res.data.img_url
                    }
                })
                .catch(err => { });
        },

        getCouponInfo() {
            let params = {
                id: this.$route.query.id
            };
            this.$post("/coupon/get_detaile", params)
                .then(res => {
                    if (res.code === 20000) {
                        this.couponSource = res.data
                        this.getShareConfig()
                    }
                })
                .catch(err => { });
        },
        getShareConfig() {
            let params = {
                // url: location.href.split('#')[0],
                url: 'http://wangzhuan.3todo.cn/',
            };
            this.$post("/index/share", params)
                .then(res => {
                    if (res.code === 20000) {
                        let shareConfig = {
                            title: this.couponSource.title,
                            descr: this.couponSource.desc,
                            icon: this.couponSource.images,
                            url: 'http://wangzhuan.3todo.cn/?share_id=' + localStorage.getItem('token') + '&coupon_id=' + this.$route.query.id + '&from=123',
                        }
                        wxShare(res.data, shareConfig, this.WXShareSuccess)
                    }
                })
                .catch(err => { });
        },
        WXShareSuccess() {
            this.$dialog.toast({ mes: '分享成功', timeout: 1000 });
        }
    },
    beforeCreate() {
        document.querySelector("body").setAttribute("style", "background-color:#fff");
    },
    created() {
        this.getImages()
        this.getCouponInfo()

    },
};
</script>
<style lang="less" scoped>
.share-img {
    position: fixed;
    top: 0;
    width: 100%;
    height: 100%;
    img {
        width: 100%;
        height: 100%;
    }
}
</style>